<template>
    <view
        v-if="load_complete"
        :style="'background:url(' + scoring_info.wechat_judge_background + ') no-repeat;background-size:  100% 100%; width: 100%;height: 100%; position: relative;'"
    >
        <view style="height: 90%; width: 90%; margin: 5%; position: absolute; background: #fff; overflow-y: scroll; border-radius: 10px">
            <!-- <view class="player-title">你好，{{judge_info.name}}</view> -->
            <view class="player-name" @tap="refresh">{{ player_info.sort ? '编号：' + player_info.sort : '' }} {{ player_info.name }}</view>
            <view class="player-photo"><image class="user_img" :lazyLoad="true" mode="aspectFill" :src="player_info.avatar"></image></view>

            <block v-if="is_score == 1">
                <view
                    class="w_100 p_s_b h2 judges"
                    :style="'padding:20px 0 0 0;color:' + (color_one ? color_one : '#CCAB69') + ';border-bottom:1px solid #eee; width: 90%;margin: 0 auto;'"
                >
                    <view style="padding: 15px 0px; line-height: 20px; border-top: 1px solid #eee" class="judges_title">
                        <text style="font-size: 16px; font-weight: bold">评委点评结果</text>
                        <text style="float: right; font-size: 14px; color: #333">得分结果：{{ player_info.total_score }}分</text>
                    </view>
                    <view style="padding: 10px 0px; position: relative; border-top: 1px solid #eee" class="judges_one" v-for="(value, index) in score_list" :key="index">
                        <view style="padding-bottom: 10px">
                            <h2 :style="'color: ' + (color_one ? color_one : '#CCAB69') + ';'">{{ value.judge_name }}：</h2>
                            <text style="color: #333">{{ value.total_score }}分</text>
                            <!-- <text style="float: right;color: #ccc;font-size: 12px;">{{value.add_time}}</text> -->
                        </view>

                        <view style="color: #333">评语：{{ value.comment }}</view>
                    </view>
                </view>
            </block>
            <block v-else-if="">
                <view class="player-doscore-item" v-for="(item, index) in item_list" :key="index">
                    <text class="player-doscore-item-name">{{ item.item_name }}</text>

                    <view class="player-doscore-item-score">
                        <slider @change="bindchange" :data-index="index" :min="item.min" :max="item.max" step="1" show-value value="" @changing="bindchange" />
                    </view>
                </view>
                <view class="player-doscore-total" v-if="total_score">
                    <text class="player-doscore-item-name">得分结果</text>
                    <text class="player-doscore-item-score">{{ total_score }} 分</text>
                </view>
                <view class="player-doscore-comment">
                    <text class="player-doscore-item-name">评语</text>
                    <textarea
                        @blur="bindTextAreaBlur"
                        @input="bindTextAreaBlur"
                        placeholder="请输入评语~"
                        style="height: 60px; width: 100%; border: 1px solid #eee; border-radius: 5px; padding: 3px"
                    />
                </view>
                <view class="player-doscore-submit">
                    <button type="primary" @tap="doScore">确 定</button>
                </view>
            </block>
        </view>
    </view>
</template>

<script>
var undefined;
var undefined;
var app = getApp();
// wxz_wzbagent/pages/live_scoring/doscore.js
export default {
    data() {
        return {
            player_id: '',
            scoring_info: [],
            judge_info: '',
            openid: '',
            player_info: [],
            item_list: [],
            load_complete: 0,
            is_score: '',
            score_list: '',
            total_score: '',
            comment: '',
            color_one: false,

            value: {
                judge_name: '',
                total_score: '',
                comment: ''
            }
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        this.onLoadClone3389(options);
    },
    onPullDownRefresh: function () {
        this.refresh();
        uni.stopPullDownRefresh();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        /**
         * 生命周期函数--监听页面加载
         */
        onLoadClone3389(options) {
            uni.hideHomeButton();
            const that = this;
            uni.login({
                success: function (res) {
                    app.globalData.util.request({
                        url: 'live_scoring&r=playerInfo',

                        data: {
                            player_id: options.id,
                            code: res.code
                        },

                        cachetime: '0',
                        showLoading: 0,

                        success: function (t) {
                            that.setData({
                                player_id: options.id,
                                openid: t.data.data.openid,
                                judge_info: t.data.data.judge_info,
                                player_info: t.data.data.player_info,
                                scoring_info: t.data.data.scoring_info,
                                item_list: t.data.data.item_list,
                                is_score: t.data.data.is_score,
                                score_list: t.data.data.score_list,
                                load_complete: 1
                            });
                            uni.setNavigationBarTitle({
                                title: t.data.data.player_info.name + '评分页'
                            });
                        }
                    });
                }
            });
        },

        bindchange(t) {
            const that = this;
            const index = t.currentTarget.dataset.index;
            const value = t.detail.value;
            const item_count = this.item_list.length;
            if (item_count == 1) {
                var total_score = value;
            }
            that.total_score_index = value;
            that.setData({
                total_score: total_score
            });
        },

        bindTextAreaBlur: function (e) {
            console.log(e);
            this.setData({
                comment: e.detail.value
            });
        },

        doScore() {
            const that = this;
            if (!that.total_score) {
                uni.showToast({
                    title: '请先进行评分',
                    icon: 'error',
                    duration: 3000
                });
                return;
            }
            var postData = {};
            postData['player_id'] = that.player_id;
            postData['scoring_id'] = that.scoring_info.id;
            postData['judge_id'] = that.judge_info.id;
            postData['total_score'] = that.total_score;
            postData['item_count'] = that.item_list.length;
            postData['comment'] = that.comment;
            for (i = 0; i < that.item_list.length; i++) {
                postData['total_score_' + i] = that['total_score_' + i];
            }
            console.log(postData);
            app.globalData.util.request({
                url: 'live_scoring&r=doScore',
                data: postData,
                cachetime: '0',
                showLoading: 0,
                success: function (t) {
                    that.onLoadClone3389(that.options, {});
                }
            });
        },

        refresh() {
            this.onLoadClone3389(this.options, {});
        }
    }
};
</script>
<style>
@import './doscore.css';
</style>
